package com.scfire.project

import org.grails.databinding.BindingFormat

import com.scfire.fund.FDonate
import com.scfire.security.Member

/**
 * Copyright 2015 Shudao Info Tech Co. Ltd.  All rights reserved.
 * @author lhzeng
 * @email zenglh@haoshudao.com
 * @date 2015年6月7日 下午10:32:36
 * @version V1.0
 */

class Donate implements Comparable  {
	
	//捐赠编号  UUID
	String donateNo	
	//捐赠编号，改为12位以内的唯一捐赠码，期望在8位，跟项目ID和用户ID有关联
	String donateNoNew
	//捐赠总金额（包含品台管理费）
	float money
	//捐赠金额
	float donate_fee
	//平台管理费
	float operate_fee
	//是否包含平台管理费
	boolean operate_fee_status
	//捐赠支付状态（未支付 false 、已支付true）
	boolean status = false
	
    //捐赠时间
	@BindingFormat('yyyy-MM-dd HH:mm')
	Date date
	
	
	//订单号
	String out_trade_no
	//支付用户的openid
	String openid
	//微信支付单号     支付宝不存在该字段
	String transaction_id
	//商家数据包    productid # memberid
	String attach
	//支付类型
	String type
	
	int member
	
	int project 
	
	int subProject
	
	//捐赠的用户及捐赠的项目,一起捐子项目
	//static belongsTo = [member:Member,project:Project,subProject:SubProject]
	
	//static hasOne = [comment:Comment,fDonate:FDonate]

    static constraints = {
		donateNo nullable:false
		donateNoNew nullable:true
		money nullable:true
		donate_fee nullable:true
		operate_fee nullable:true
		operate_fee_status nullable:true
		status nullable:false
		date nullable:false
		
		out_trade_no nullable:true , unique : true
		openid nullable:true
		transaction_id nullable:true
		attach nullable:true
		type nullable:true
		
		project nullable:false
		member nullable:false
		//comment nullable:true
		subProject nullable:true
		//fDonate  nullable:true
		
    }
	
	/*static mapping = {
		id generator:'assigned', name: 'donateId'
		version true
	}*/
	
	public int compareTo(Object o) {
		try{
			-date.compareTo(o?.date)
		}catch(Exception e){
			return 1
		}
	}
}
